package com.ailot.cloud.mall.controller;

import com.ailot.cloud.base.common.dto.Result;
import com.ailot.cloud.base.log.annotation.Oplog;
import com.ailot.cloud.mall.entity.DeliveryPlace;
import com.ailot.cloud.mall.service.DeliveryPlaceService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 发货地
 *
 * @Author ailot
 * @create 2024-11-14
 */

@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/deliveryplace")
public class DeliveryPlaceController {

    private final DeliveryPlaceService deliveryPlaceService;

    /**
     * 分页
     */
    @GetMapping("/page")
    public Page<DeliveryPlace> getDeliveryPlacePage(Page<DeliveryPlace> page, DeliveryPlace deliveryPlace) {
        return deliveryPlaceService.page(page, Wrappers.query(deliveryPlace));
    }

    /**
     * 新增
     */
    @Oplog("新增")
    @PostMapping
    public Boolean save(@Valid @RequestBody DeliveryPlace deliveryPlace) {
        return deliveryPlaceService.save(deliveryPlace);
    }

    /**
     * 修改
     */
    @Oplog("修改")
    @PutMapping
    public Boolean update(@Valid @RequestBody DeliveryPlace deliveryPlace) {
        return deliveryPlaceService.updateById(deliveryPlace);
    }

    /**
     * 删除
     */
    @Oplog("删除")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable String id) {
        return Result.success(deliveryPlaceService.removeById(id));
    }


    @GetMapping("/list")
    public List<DeliveryPlace> list() {
        return deliveryPlaceService.list();
    }
}